package com.mycat.redis.stuff;

import com.dyuproject.protostuff.LinkedBuffer;
import com.dyuproject.protostuff.ProtostuffIOUtil;
import com.dyuproject.protostuff.Schema;
import com.dyuproject.protostuff.runtime.RuntimeSchema;
import com.mycat.redis.util.JedisUtil;

import java.util.Date;

/**
 * ${DESCRIPTION}
 *
 * @author roger.
 * @email 190642964@qq.com
 * @create 2016-12-21
 */
public class ProtostuffTest {


    public static void main(String[] args) {

        ProtostuffTest.localTest();

    }

    public static void localTest() {
        MyCat myCat = new MyCat(1, "name2", new Date());

        // 通过protostuff序列化
        Schema<MyCat> schema = RuntimeSchema.getSchema(MyCat.class);
        LinkedBuffer linkedBuffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);

        byte[] bytes = ProtostuffIOUtil.toByteArray(myCat, schema, linkedBuffer);



        JedisUtil.JedisStringUtil.set(ProtosuffUtil.serialize("myCattest"), bytes);
        byte[] getBytes = JedisUtil.JedisStringUtil.get(ProtosuffUtil.serialize("myCattest"));

        System.out.println(ProtosuffUtil.deserialize(getBytes, MyCat.class));

    }

}
